1930A - Maximise The Score - CodeForces Solution


greedy sortings

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    ll t;
    cin>>t;
    for(int j=0;j<t;j++){
        ll n;
        cin>>n;
        vector<int> v;
        for(int i=0;i<2*n;i++){
            int x;
            cin>>x;
            v.push_back(x);
        }

        sort(v.begin(),v.end());

        ll sum = 0;

        for(int i=0;i<2*n;i=i+2){
            sum = sum + min(v[i],v[i+1]);
        }

        cout<<sum<<endl;
    }
    
    return 0;
}


Comments

Submit
0 Comments
More Questions

1733A - Consecutive Sum
1733B - Rule of League
1733C - Parity Shuffle Sorting
1264A - Beautiful Regional Contest
1695A - Subrectangle Guess
467B - Fedor and New Game
252C - Points on Line
735C - Tennis Championship
992A - Nastya and an Array
554A - Kyoya and Photobooks
79B - Colorful Field
265B - Roadside Trees (Simplified Edition)
1362C - Johnny and Another Rating Drop
1214C - Bad Sequence
1091B - New Year and the Treasure Geolocation
244A - Dividing Orange
1061C - Multiplicity
1312A - Two Regular Polygons
801A - Vicious Keyboard
510B - Fox And Two Dots
616D - Longest k-Good Segment
1604A - Era
555B - Case of Fugitive
551A - GukiZ and Contest
1399F - Yet Another Segments Subset
1371C - A Cookie for You
430B - Balls Game
1263A - Sweet Problem
1332B - Composite Coloring
254A - Cards with Numbers